package com.tnovoselec.android.travelassistant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.android.maps.GeoPoint;
import com.tnovoselec.android.lbs.location.DistanceCalculator;
import com.tnovoselec.android.travelassistant.dto.MeteoFavoritesDto;

public class Util {

	public static MeteoFavoritesDto getNearestCityMeteoData(GeoPoint location, List<MeteoFavoritesDto> meteos) {

		double dist = 0;
		MeteoFavoritesDto meteoToReturn = null;
		if (location == null) {
			return meteoToReturn;
		}
		for (MeteoFavoritesDto meteo : meteos) {
			double tempDist = DistanceCalculator.distance(location, new GeoPoint((int) (meteo.getLat() * 1e6), (int) (meteo.getLng() * 1e6)));
			if (Double.compare(dist, tempDist) > 0 || Double.compare(dist, 0) == 0) {
				meteoToReturn = meteo;
				dist = tempDist;
			}
		}

		return meteoToReturn;
	}

	public static List<MeteoFavoritesDto> sortCities(GeoPoint location, List<MeteoFavoritesDto> meteos) {

		List<MeteoFavoritesDto> meteosCopy = new ArrayList<MeteoFavoritesDto>(meteos);

		MeteoFavoritesDto meteo1 = null;
		MeteoFavoritesDto meteo2 = null;
		if (location == null) {
			return meteos;
		}
		for (int i = 0; i < meteosCopy.size(); i++) {
			meteo1 = meteosCopy.get(i);
			for (int j = 0; j < meteosCopy.size(); j++) {
				meteo2 = meteosCopy.get(j);
				double tempDist1 = DistanceCalculator.distance(location, new GeoPoint((int) (meteo1.getLat() * 1e6), (int) (meteo1.getLng() * 1e6)));
				double tempDist2 = DistanceCalculator.distance(location, new GeoPoint((int) (meteo2.getLat() * 1e6), (int) (meteo2.getLng() * 1e6)));
				if (Double.compare(tempDist1, tempDist2) < 0) {
					swap(meteosCopy, j, i);
				}
			}
		}

		return meteosCopy;
	}

	private static void swap(List<MeteoFavoritesDto> list, int firstInd, int secondInd) {
		MeteoFavoritesDto temp = list.set(firstInd, list.get(secondInd));
		list.set(secondInd, temp);
	}

	public static String getARTypeName(String type) {
		String retval = "";
		if (type.indexOf(" ") == -1 && type.indexOf("-") == -1) {
			retval = type;
		} else {
			if (type.indexOf("-") != -1) {
				retval = type.substring(0, type.indexOf("-"));
			} else {
				retval = type.substring(0, type.indexOf(" "));
			}
		}
		// Log.i("util", retval);
		return retval;
	}

	public static Map<String, String> conditions = new HashMap<String, String>();

	static {
		conditions.put("296", "Mogući pljusak");
		conditions.put("293", "Mogući pljusak");
		conditions.put("185", "Mogući pljusak");
		conditions.put("113", "Sunčano");
		conditions.put("116", "Djelomično oblačno");
		conditions.put("119", "Oblačno");
		conditions.put("143", "Izmaglica");
		conditions.put("200", "Oluja s grmljavinom");
		conditions.put("368", "Susnježica");
		conditions.put("365", "Susnježica");
		conditions.put("362", "Susnježica");
		conditions.put("326", "Susnježica");
		conditions.put("323", "Susnježica");
		conditions.put("320", "Susnježica");
		conditions.put("314", "Susnježica");	
		conditions.put("317", "Susnježica");	
		conditions.put("182", "Susnježica");	
		conditions.put("350", "Pljusak");
		conditions.put("395", "Snijeg");
		conditions.put("392", "Snijeg");
		conditions.put("338", "Snijeg");
		conditions.put("371", "Snijeg");	
		conditions.put("335", "Snijeg");
		conditions.put("332", "Snijeg");	
		conditions.put("329", "Snijeg");
		conditions.put("230", "Snijeg");
		conditions.put("227", "Snijeg");	
		conditions.put("179", "Snijeg");	
		conditions.put("260", "Magla");
		conditions.put("248", "Magla");
		conditions.put("386", "Blaga kiša");	
		conditions.put("353", "Blaga kiša");
		conditions.put("122", "Oblačno");
		conditions.put("389", "Pljusak");
		conditions.put("377", "Pljusak");
		conditions.put("374", "Pljusak");
		conditions.put("359", "Pljusak");	
		conditions.put("356", "Pljusak");
		conditions.put("350", "Pljusak");
		conditions.put("311", "Pljusak");
		conditions.put("176", "Pljusak");
		conditions.put("308", "Pljusak");	
		conditions.put("305", "Pljusak");
		conditions.put("302", "Pljusak");
		conditions.put("299", "Pljusak");
		conditions.put("284", "Pljusak");
		conditions.put("281", "Pljusak");
		conditions.put("266", "Pljusak");
		conditions.put("263", "Pljusak");
	}

	public static Map<String, String> daysOfWeek = new HashMap<String, String>();
	static {
//		daysOfWeek.put("mon", "Pon");
//		daysOfWeek.put("thu", "Uto");
//		daysOfWeek.put("wed", "Sri");
//		daysOfWeek.put("thu", "ÄŒet");
//		daysOfWeek.put("fri", "Pet");
//		daysOfWeek.put("sat", "Sub");
//		daysOfWeek.put("sun", "Ned");
		
		daysOfWeek.put("2", "Pon");
		daysOfWeek.put("3", "Uto");
		daysOfWeek.put("4", "Sri");
		daysOfWeek.put("5", "Čet");
		daysOfWeek.put("6", "Pet");
		daysOfWeek.put("7", "Sub");
		daysOfWeek.put("1", "Ned");
	}
	
	public static Map<String, String> currencyNames = new HashMap<String, String>();
	static {
		currencyNames.put("AUD", "Australski dolar");
		currencyNames.put("BAM", "Bosanska marka");
		currencyNames.put("CAD", "Kanadski dolar");
		currencyNames.put("CHF", "Švicarski franak");
		currencyNames.put("CZK", "Češka kruna");
		currencyNames.put("DKK", "Danska kruna");
		currencyNames.put("EUR", "Euro");
		currencyNames.put("GBP", "Britanska funta");
		currencyNames.put("HRK", "Hrvatska kuna");
		currencyNames.put("HUF", "Madžarski forint");
		currencyNames.put("JPY", "Japanski jen");
		currencyNames.put("NOK", "Norveška kruna");
		currencyNames.put("PLN", "Poljski zloti");
		currencyNames.put("SEK", "Švedska kruna");
		currencyNames.put("USD", "Američki dolar");
	}

}
